package org.geektimes.projects.user.web.controller;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.repository.HomeworkUserRepository;
import org.geektimes.projects.user.repository.UserRepository;
import org.geektimes.projects.user.service.impl.UserServiceImpl;
import org.geektimes.web.mvc.controller.RestController;

import javax.annotation.Resource;
import javax.ws.rs.Path;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 @author :   chuan
 @date :   2021/0
 */
public class RegistryRestController implements RestController {

    @Resource(name = "bean/UserServiceImpl")
    private UserServiceImpl userService;

    /**
      默认： HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, HttpMethod.OPTIONS
     */
    @Path("/doAjaxRegistry")
    public Object doRegistry(String name,
                             String password,
                             String email,
                             String phoneNumber) throws SQLException {

        User user = new User();
        user.setName(name);
        user.setPassword(password);
        user.setEmail(email);
        user.setPhoneNumber(phoneNumber);

        userService.register(user);

        Map<String, Object> result = new HashMap<>(2);
        result.put("sc", 10000);
        result.put("message", "Registry Success");

        return result;
    }
}
